package net.es.weathermap.topo.sites;

import java.util.*;

import org.apache.log4j.Logger;

import net.es.weathermap.util.ConfigHelper;

/**
 * Singleton to store site information map.
 * @author David Robertson, Evangelos Chaniotakis
 */
public class SiteInfo {

    private static SiteInfo instance;
    private static final String DEFAULT_INFO_FILE = "sites.yaml";

    private Logger log;
    private HashMap<String, HashMap<String, String>> sites;

    /**
     * Constructor - private because this is a Singleton
     */
    private SiteInfo() {
        this.log = Logger.getLogger(this.getClass());
    }

    /**
     * @return the initialized SiteInfo singleton instance
     */
    public static SiteInfo getInstance() {
        if (SiteInfo.instance == null) {
            SiteInfo.instance = new SiteInfo();
            SiteInfo.instance.setSites(DEFAULT_INFO_FILE);
        }
        return SiteInfo.instance;
    }

    public HashMap<String, HashMap<String, String>> getSites() {
        return this.sites;
    }

    private void setSites(String fname) {
        ConfigHelper cfg = ConfigHelper.getInstance();
        Map yamlMap = cfg.getConfiguration(fname);
        assert yamlMap != null:  "Could not load soap configuration file from " +
            "file: ${basedir}/config/" + DEFAULT_INFO_FILE;
        this.sites = (HashMap<String, HashMap<String, String>>) yamlMap;
    }
}
